package com.zhentao.config;

import com.zhentao.interceptor.LoginInterceptor;
import com.zhentao.interceptor.RefreshTokenInterceptor;
import com.zhentao.redis.CacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName: MvcConfig
 * @Author: 振涛教育_Q
 * @Date: 2024/11/18 9:31
 */
@Configuration
@Slf4j
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/api/user/loginUser",
                        "/api/user/admin/login",
                        "/api/user/loginManage",
                        "/api/user/sendCaptcha",
                        "/api/user/forgetPassword",
                        "/api/user/updatePassword-user",
                        "/api/files/select",
                        "/api/upload-image",
                        "/api/upload"
                ).order(1);
        registry.addInterceptor(new RefreshTokenInterceptor(redisTemplate)).addPathPatterns("/**").order(0);
    }
}
